//
//  YXHomeViewModel.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/29.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXHomeViewModel.h"
#import "YXBannerModel.h"
#import "YXUserInfoModel.h"
#import "YXTradingModel.h"
#import "YXTerminalsModel.h"
#import "YXPartnerModel.h"
@interface YXHomeViewModel ()

@end
@implementation YXHomeViewModel



+ (void)getQuerySelectBannerListCategory:(NSString *)category Type:(NSString *)type ModelList:(void(^)(NSArray *,YXBannerModel *))mdList Failure:(void(^)(NSError *error))failure {
    
    
//    http://121.196.210.134:8082/mpos/wx/selectBannerList.do
//    http://121.196.210.134:8082/mpos/wx/selectNoticeType.do?type=3
    NSString *urlStr;
    NSDictionary *parameter;
    if ([category isEqualToString:@"1"]) {
        urlStr =  @"selectNoticeType.do";
        parameter = @{@"type":type};
    }else {
        urlStr =  @"selectBannerList.do";
    }
    
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:[category isEqualToString:@"2"] ? nil : parameter success:^(id responseObject) {
        
        if ([category isEqualToString:@"1"]) {
            if (REQUESTDATASUCCESS) {
                YXBannerModel *model = [YXBannerModel mj_objectWithKeyValues:responseObject[@"body"]];
                if (mdList) {
                    mdList(nil,model);
                }
            }
            
        }else {
            if (REQUESTDATASUCCESS) {
                NSMutableArray *dataArr = [NSMutableArray array];
                for (NSDictionary *dict in responseObject[@"body"]) {
                    YXBannerModel *model = [[YXBannerModel alloc] init];
                    [model setValuesForKeysWithDictionary:dict];
                    [dataArr addObject:model.imgUrl];
                }
                if (mdList) {
                    mdList(dataArr,nil);
                }
                
            }
        }
    
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}



+ (void)getQueryMerchantNumberSessionId:(NSString *)sessionId ModelList:(void(^)(YXPartnerModel *model))mdList Failure:(void(^)(NSError *error))failure {
    NSString *urlStr = @"getMerchantNumber.do";
    NSDictionary *paramter = @{@"sessionId":sessionId};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:paramter success:^(id responseObject) {
//        NSLog(@"%@",responseObject);
        if (REQUESTDATASUCCESS) {
            YXPartnerModel *model = [YXPartnerModel mj_objectWithKeyValues:responseObject[@"body"]];
            if (mdList) {
                mdList(model);
            }
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        if (failure) {
            failure(error);
        }
    }];
}




+ (void)getQueryFindMerchantListSessionId:(NSString *)sessionId PageNo:(NSString *)pageNo Name:(NSString *)name ModelList:(void(^)(NSArray *listArr))mdList Failure:(void(^)(NSError *error))failure {
    
    //http://121.196.210.134:8082/mpos/wx/findMerchantList.do?sessionId=0b737ceb-7453-4327-b460-3627ce73a8df&pageNo=1&pageSize=10&name=%E5%AE%8B
    NSString *urlStr = @"findMerchantList.do";
    NSDictionary *paramter = @{@"sessionId":sessionId,@"pageNo":pageNo,@"pageSize":@"10",@"name":name};
//    NSDictionary *paramter = @{@"sessionId":sessionId,@"pageNo":pageNo,@"pageSize":@"10"};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:paramter success:^(id responseObject) {
//        NSLog(@"请求成功:%@",responseObject);
        if (REQUESTDATASUCCESS) {
            NSArray *listArr = [YXUserInfoModel mj_objectArrayWithKeyValuesArray:responseObject[@"body"][@"list"]];
            
            if (mdList) {
                mdList(listArr);
            }
        }

    } failure:^(NSError *error) {
        NSLog(@"请求失败:%@",error);
        if (failure) {
            failure(error);
        }
    }];
    
    
}

+ (void)getQueryGetMeAndNextAgentsSessionId:(NSString *)sessionId  ModelList:(void(^)(NSArray *listArr))mdList Failure:(void(^)(NSError *error))failure {
    //http://121.196.210.134:8082/mpos/wx/getMeAndNextAgents.do
    NSString *urlStr = @"getMeAndNextAgents.do";
    NSDictionary *paramter = @{@"sessionId":sessionId};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:paramter success:^(id responseObject) {
//        NSLog(@"请求成功:%@",responseObject);
        if (REQUESTDATASUCCESS) {
            NSArray *listArr = [YXUserInfoModel mj_objectArrayWithKeyValuesArray:responseObject[@"body"]];
            
            if (mdList) {
                mdList(listArr);
            }
        }
        
    } failure:^(NSError *error) {
        NSLog(@"请求失败:%@",error);
        if (failure) {
            failure(error);
        }
    }];

}



+ (void)getQueryfindRecordsofConsumptionSessionId:(NSString *)sessionId Pid:(NSString *)pid PageNo:(NSString *)pageNo typ:(NSString *)typ Data:(NSString *)data ModelList:(void(^)(NSArray *listArr))mdList Failure:(void(^)(NSError *error))failure {
    
    //http://121.196.210.134:8082/test_mpos/wx/findMerchantList.do?sessionId=9148a2d2-a41e-4a6e-bda6-ead496241000&pid=100004&pageNo=1&pageSize=10&typ=-1&data=true
    NSString *urlStr = @"findRecordsofConsumption.do";
    NSDictionary *paramter = @{@"sessionId":sessionId,@"pid":pid,@"pageNo":pageNo,@"pageSize":@"20",@"typ":typ,@"data":data};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:paramter success:^(id responseObject) {
//        NSLog(@"请求成功:%@",responseObject);
        if (REQUESTDATASUCCESS) {
            NSArray *listArr = [YXTradingModel mj_objectArrayWithKeyValuesArray:responseObject[@"body"][@"list"]];
            
            if (mdList) {
                mdList(listArr);
            }
        }
        
    } failure:^(NSError *error) {
        NSLog(@"请求失败:%@",error);
        if (failure) {
            failure(error);
        }
    }];
    
}

+ (void)getQueryGetTerminalsModel:(NSString *)model pageNo:(NSString *)pageNo state:(NSString *)state startTerminalCode:(NSString *)startTerminalCode endTerminalCode:(NSString *)endTerminalCode ModelList:(void(^)(NSArray *listArr, NSString *totalCount))mdList Failure:(void(^)(NSError *error))failure {
    
    //    http://121.196.210.134:8082/mpos/wx/getTerminals.do?sessionId=137c9a34-d907-47f1-8e9a-56a8457a741f&pageNo=1&pageSize=10&state=0&startTerminalCode=8&endTerminalCode=1&model=M7
    NSString *urlStr = @"getTerminals.do";
    NSDictionary *parameter = @{@"sessionId":[YXUserInfoManager getUserInfo].sessionId,@"pageNo":pageNo,@"pageSize":@"20",@"state":state,@"startTerminalCode":startTerminalCode,@"endTerminalCode":endTerminalCode,@"model":model};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:parameter success:^(id responseObject) {
//        NSLog(@"%@",responseObject);
        if (REQUESTDATASUCCESS) {
            NSArray *listArr = [YXTerminalsModel mj_objectArrayWithKeyValuesArray:responseObject[@"body"][@"list"]];
            NSString *totalCountStr = responseObject[@"body"][@"totalCount"];
            if (mdList) {
                mdList(listArr,totalCountStr);
            }
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        if (failure) {
            failure(error);
        }
    }];
}


+ (void)getQueryAllotTerminalsSessionId:(NSString *)sessionId startTerminalCode:(NSString *)startTerminalCode endTerminalCode:(NSString *)endTerminalCode agentid:(NSString *)agentid  ModelList:(void(^)(NSArray *listArr))mdList Failure:(void(^)(NSError *error))failure {
    //http://121.196.210.134:8082/mpos/wx/allotTerminals.do
    NSString *urlStr = @"allotTerminals.do";
    NSDictionary *parameter = @{@"sessionId":sessionId,@"startTerminalCode":startTerminalCode,@"endTerminalCode":endTerminalCode,@"agentid":agentid};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:parameter success:^(id responseObject) {
        NSLog(@"%@",responseObject);
        if (REQUESTDATASUCCESS) {
            NSArray *arr;
            if (mdList) {
                mdList(arr);
            }
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        if (failure) {
            failure(error);
        }
    }];
    
}


+ (void)getQueryGetGrossProfitPid:(NSString *)pid ModelList:(void(^)(NSString *body))mdList Failure:(void(^)(NSError *error))failure {
    //http://121.196.210.134:8082/mpos/wx/getGrossProfit.do
    NSString *urlStr = @"getGrossProfit.do";
    NSDictionary *paramter = @{@"pid":pid};
    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:paramter success:^(id responseObject) {
//        NSLog(@"请求成功:%@",responseObject);
        if (REQUESTDATASUCCESS) {
                    
        }
        
    } failure:^(NSError *error) {
//        NSLog(@"请求失败:%@",error);
        
    }];

    
}





@end
